<?php

class User_IndexController extends Zend_Controller_Action
{

    public function init()
    {
    	try{
	    	$dirTemplate = TEMPLATE_PATH;
	    	$sectionConfig = 'template';
	    	$fileConfig = 'default/template.ini';
	    	$this->createTemplate($dirTemplate, $sectionConfig, $fileConfig );
    	}catch(Exception $ex){
    		echo "error: ".$ex->getMessage();
    		die;
    	}
    }
    
    public function createTemplate($dirTemplate, $sectionConfig = 'template', $fileConfig = 'default/template.ini' ){
    	try{
	    	$module =$this->getRequest()->getModuleName();
	    	$filename = $dirTemplate . '/'.$module.'/' . $fileConfig;
	
	    	$section = $sectionConfig;
	    	$config = new Zend_Config_Ini($filename, $section);
	    	$config = $config->toArray();
	    
	    	$baseUrl = $this->_request->getBaseUrl();
	    	$dirTemplateUrl = $baseUrl . $config['url'];
	    	
	    	$dirJs = $dirTemplateUrl . $config['dirJs'];
	    	
	//     	echo "<br/>".$this->view->dirCss = $dirTemplateUrl . $config['dirCss'];
	//     	echo "<br/>".$this->view->dirImg = $dirTemplateUrl . $config['dirImg'];
	//     	echo "<br/>".$this->view->dirJs = $dirTemplateUrl . $config['dirJs'];
	
	    	$this->view->dirCss = $dirTemplateUrl . $config['dirCss'];
	    	$this->view->dirImg = $dirTemplateUrl . $config['dirImg'];
	    	$this->view->dirJs = $dirTemplateUrl . $config['dirJs'];
	    	
	    	
	    	$option = array('layout'=> $config['layout'],
	    			//'layoutPath'=>PUBLIC_PATH.$config['url']);
	    			'layoutPath'=>PUBLIC_PATH.'/templates/front/default');
	    	Zend_Layout::startMvc($option);
    	}catch(Exception $ex){
    		echo "<br/> Error: ".$ex->getMessage();
    		exit;
    	}
    }

    public function indexAction()
    {
        // action body
        //echo "User module - Index Controller";
    	$baseUrl = "http://" . $this->getRequest ()->getHttpHost () ;
    	$this->view->baseurl = $baseUrl;
    	
    	$a = array();
    	for($i = 0 ;$i<= 500; ++$i){
    		if( in_array(mt_rand(5, 99999999), $a)){
    			
    			echo "trung roi";
    			break;
    		}else{
    			$a[] = mt_rand(5,99999999);
    		}
    	}
    	
    	$mang = array_count_values($a);
    	foreach($mang as $key=>$value){
    		if($value > 1){
    			echo $key."=>".$value;
    			break;
    		}
    	}
    }
    
    public function loginAction(){
    	
    	
    }

    public function registerAction(){
    	
    }

}

